package edu.song.yeb.boot.config.security;

import edu.song.yeb.boot.domain.Admin;
import edu.song.yeb.boot.service.AdminService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

@Component
public class LoginUserService implements UserDetailsService {

    @Resource
    private AdminService adminService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Admin admin = this.adminService.findAdminByUsername(username);
        if(Objects.isNull(admin)){
            throw new UsernameNotFoundException("账号或密码错误！");
        }
        //获取权限
        return admin;
    }
}
